<template>
    <view class="content">
        <view class="nav">
            <view class="nav-i" :class="{active : type == 1}" @click="chooseNav(1)">未使用</view>
            <view class="nav-i" :class="{active : type == 2}" @click="chooseNav(2)">已使用</view>
            <view class="nav-i" :class="{active : type == 3}" @click="chooseNav(3)">已过期</view>
        </view>
        
        <view class="item" v-for="(item, index) in list" :key="index">
            <image src="../../static/image/g_coupon.png" class="img" v-if="type == 1"></image>
            <image src="../../static/image/g_coupon2.png" class="img" v-else></image>
            <view class="u-flex-1">
                <view class="price" :class="{pA : type == 2 || type == 3}">
                    ￥<text>{{item.offset_price}}</text>满{{item.limit_price}}元使用
                </view>
                <view class="time">使用时间：{{item.pbegin}}至{{item.pend}}</view>
                <view class="down">
                    <view class="u-flex-1">规则说明：{{item.description}}</view>
                    <view class="btn" v-if="type == 1" @click="$sTo(`/pages/tabbar/index`)">立即使用</view>
                </view>
            </view>
        </view>
        
        <view style="height: 94rpx;padding-top: 30rpx;">
            <u-loadmore :status="status" v-if="status != 'loadmore'" />
        </view>
    </view>
</template>

<script>
    export default {
        data() {
            return {
                type: 1,
                status: 'loadmore', //是否显示没有更多了
                page: 1,
                list: [],
            };
        },
        onLoad(option) {
            this.getList()
        },
        onReachBottom() {
        	if(this.page == 1){return}
        	this.getList()
        },
        methods: {
            chooseNav(num) {
                if (this.type == num) return
                this.type = num
                this.list = []
                this.page = 1
                this.status = 'loadmore'
                this.getList()
            },
            
            getList() {
            	if (this.status == 'nomore') return;
            	this.status = 'loading';
            	this.$ajax('couponme', {
                    userToken: this.$getSync('userToken'),
                    page: this.page,
                    limit: 10,
                    type: this.type,//优惠券状态 1-未使用 2-已使用 3-已过期
                }).then(ret => {
            		if (ret.status == 0) {
                        if (ret.data.length > 0) {
                        	this.list = this.list.concat(ret.data);
                        	this.page++;
                        	this.status = 'loadmore'
                        } else {
                        	this.status = 'nomore'
                        }
            		} else {
            			this.$toast(ret.message);
            		}
            	});
            },
        }
    };
</script>

<style lang="scss">
    
    page{
        background-color: #f9f9f9;
    }
    .content{
        padding-bottom: 50rpx;
    }
    .nav{
        border-top: 2rpx solid #ebebeb;
        background-color: #fff;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }
    .nav-i{
        width: calc(100vw / 3);
        padding: 30rpx 0;
        font-size: 28rpx;
        text-align: center;
    }
    .active{
        font-size: 32rpx;
        font-weight: bold;
        color: #00734c;
        border-bottom: 2rpx solid #00734c;
    }
    
    .item{
        display: flex;
        justify-content: space-between;
        align-items: center;
        background-color: #fff;
        padding: 30rpx 25rpx;
        margin: 20rpx 20rpx 0;
        border-radius: 20rpx;
    }
    .img{
        width: 140rpx;
        height: 140rpx;
        margin-right: 18rpx;
    }
    .price{
        font-size: 26rpx;
        color: #f62a2a;
    }
    .price>text{
        font-size: 56rpx;
        font-weight: bold;
        padding-right: 5rpx;
    }
    .pA{
        color: #5e5d5d;
    }
    .time{
        font-size: 24rpx;
        color: #4c4c4c;
        padding-bottom: 15rpx;
    }
    .down{
        padding-top: 20rpx;
        border-top: 2rpx dashed #cccccc;
        display: flex;
        justify-content: space-between;
        align-items: center;
        font-size: 24rpx;
        color: #999999;
    }
    .btn{
        font-size: 24rpx;
        color: #8c6238;
        padding: 8rpx 10rpx;
        background-color: #f8e4cb;
        border-radius: 8rpx;
        margin-left: 20rpx;
    }
    

</style>
